Repository navigation
fix TypeScript definitions for parseUrl, agentOptions and RequestError.request, and drop the undici import - #382
Merged
glynnbird merged 2 commits intoOct 28, 2026
Conversation
…r.request. Fixes apache#362, fixes apache#380 - restore `parseUrl?: boolean` in `Configuration` and put the `headers` doc comment back above `headers` - type `agentOptions` as an undici `Dispatcher` instance, which is what nano passes to `fetch` as `dispatcher`; the previous union of constructor types rejected `new Agent()` / `new MockAgent()` and accepted values that fail with "agent.dispatch is not a function" - describe `RequestError.request` as the scrubbed fetch options nano attaches (`url`, lower-case `method`, `headers`, `body`, ...) instead of the request-era `uri`/`qs` shape Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e#381 undici is only a devDependency, so consumers without it got TS2307 from `import ... from "undici"` (or an `any`-typed `agentOptions` with skipLibCheck). Declare a structural `Dispatcher` interface instead; undici Agent, Pool, MockAgent, ProxyAgent and RetryAgent instances all satisfy it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes to
lib/nano.d.tsonly; there are no runtime changes. As agreed in #381, this combines #362, #380 and #381, because they touch the same lines.Configuration.parseUrlwas missing (parseUrloption is missing from theConfigurationtype in v11 #362). The runtime still reads it ('parseUrl' in cfg), and the README documents it. The "Set to false to prevent parsing of url" comment had ended up aboveheaders, with the "Custom request headers" comment after it. This addsparseUrl?: booleanback and puts both comments on the right properties.Configuration.agentOptionsis now a Dispatcher instance (TypeScript:agentOptionsandRequestError.requesttypes don't match the v11 runtime #380). It used to be a union ofAgentOptionsand constructor types (typeof undici.Agent, ...). nano passes the value unchanged tofetchasdispatcher, so it has to be an instance. Before this change,new Agent({...})andnew MockAgent()failed with TS2322. Passing theAgentclass or a plain options object typechecked, but every request then failed withTypeError: agent.dispatch is not a function. TheAgentOptionsinterface stays exported, so existingnano.AgentOptionsreferences keep compiling.RequestError.requestnow describes the object nano attaches (TypeScript:agentOptionsandRequestError.requesttypes don't match the v11 runtime #380). That object is the scrubbedfetchOptionsfromrelax():url(including the query string), lower-casemethod,headers,body,credentials,redirect,signal,bodyTimeout, anddispatcherwhen one is configured. This replaces the olduri/qsshape, which nano 11 never sets. All properties stay optional, like the rest ofRequestError.undiciimport (TypeScript: publishednano.d.tsimportsundici, which is only a devDependency #381). This is option 2 from the issue.nano.d.tsdeclares a structuralnano.Dispatcherinterface (dispatch(options: object, handler: object): boolean) instead ofimport undici from "undici". Consumers no longer need undici's types to compile withskipLibCheck: false, and withskipLibCheck: trueagentOptionsis no longer silentlyany. undici remains a devDependency for the test mocks.Compatibility: the only code that stops compiling is code that was already broken at runtime. That covers reading
err.request.uri/err.request.qs(alwaysundefinedin v11) and passing a class, a plain object or a non-dispatcher asagentOptions. Comparisons likeerr.request?.method === 'GET'still compile, although at runtime the method is lower case.Testing recommendations
npm testpasses (tsc lib/nano.d.tsplus 243 tests). The repo has no type-level tests, so I checked the changes with consumer projects usingmodule/moduleResolution: nodenext,strictandskipLibCheck: false.With undici 7 installed, this file compiles cleanly with this PR as both ESM and CJS (
import Nano = require('nano')). Againstmainit gives 7 × TS2322 (one per instance line), TS2353 onparseUrl, TS2339 onrequest.url, and 3 unused@ts-expect-errordirectives:Without undici installed, this compiles cleanly with this PR. Against
mainit fails withTS2307: Cannot find module 'undici'innano.d.ts:For reference, this is the runtime
err.requestfor a 404 with anAgentconfigured. I got it against a local stub server with nano 11.0.7 on Node 24.21:GitHub issue number
Fixes #362
Fixes #380
Fixes #381
Related Pull Requests
None. Separately, the README and migration guide examples pass the agent as
undiciOptions, which nano ignores, rather than asagentOptions. That's a docs fix and not part of this PR.Checklist
tsc lib/nano.d.tsinnpm test, plus the consumer snippets above; the repo has no type-test harness)nano.d.ts)This PR was prepared with Claude Code (AI-assisted, per the ASF generative tooling guidance). I reviewed the changes and checked them against
lib/nano.js.🤖 Generated with Claude Code